package com.controller;

import com.po.PermissionResourcePO;
import com.po.PermissionRolePO;
import com.result.Result;
import com.service.PermissionResourceService;
import com.service.PermissionRoleService;
import com.utils.Tree;
import com.vo.PermissionResourceVO;
import com.vo.PermissionRoleVO;
import com.vo.ResourceVO;
import com.vo.RoleDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: chihaojie
 * @Date: 2019/5/29 16:32
 * @Version 1.0
 * @Note
 */
@Api(value = "角色Api")
@CrossOrigin
@RestController
@RequestMapping("/permissionRole")
public class PermissionRoleController {



    @Autowired
    private PermissionRoleService permissionRoleService;

    @ApiOperation(value = "新增角色", httpMethod = "POST", notes = "新增角色")
    @RequestMapping(value = "/add", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<PermissionRoleVO> add(@RequestBody PermissionRolePO permissionRolePO) {
        return new Result<PermissionRoleVO>().ok(permissionRoleService.add(permissionRolePO));
    }

    @ApiOperation(value = "修改角色", httpMethod = "POST", notes = "修改角色")
    @RequestMapping(value = "/edit", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<PermissionRoleVO> edit(@RequestBody PermissionRolePO permissionRolePO) {
        return new Result<PermissionRoleVO>().ok(permissionRoleService.edit(permissionRolePO));
    }


    @ApiOperation(value = "remove", httpMethod = "GET", notes = "删除角色")
    @RequestMapping(value = "/remove", method = RequestMethod.GET)
    public Result remove(@RequestParam("id") Long  id) {
        return new Result().ok(permissionRoleService.remove(id));
    }


    /**
     * 查询角色
     */
    @ApiOperation(value = "查询角色列表", httpMethod = "GET", notes = "查询角色列表")
    @RequestMapping(value = "/getRoleList", method = RequestMethod.GET)
    public Result<List<PermissionRoleVO>> getRoleList() {
        return new Result<List<PermissionRoleVO>>().ok(permissionRoleService.getRoleList());
    }

    /**
     * 查询单个角色
     */
    @ApiOperation(value = "查询角色详情", httpMethod = "GET", notes = "查询角色详情")
    @RequestMapping(value = "/getRoleInfo", method = RequestMethod.GET)
    public Result<PermissionRoleVO> getRoleInfo(@RequestParam Long id) {
        return new Result<PermissionRoleVO>().ok(permissionRoleService.getRoleInfo(id));
    }

    /**
     * 查询单个角色
     */
    @ApiOperation(value = "查询角色详情2", httpMethod = "GET", notes = "查询角色详情2")
    @RequestMapping(value = "/getRoleDetail", method = RequestMethod.GET)
    public Result<RoleDetailVO> getRoleDetail(@RequestParam Long id) {
        return new Result<RoleDetailVO>().ok(permissionRoleService.getRoleDetail(id));
    }


}
